//
//  UILabel+FontColor.m
//  LocalGoods2
//
//  Created by 黄晓冬 on 2018/10/28.
//  Copyright © 2018年 Xiaodong Huang. All rights reserved.
//

#import "UILabel+FontColor.h"

@implementation UILabel (FontColor)

- (void)setLabelFont:(UIFont *)font toText:(NSString *)text {
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:self.text];
    NSRange range1 = [[str string] rangeOfString:text];
    [str addAttribute:NSFontAttributeName value:font range:range1];
    //[str addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:range1];
//    NSRange range2 = [[str string] rangeOfString:@"用户规则"];
//    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range2];
//    NSRange range3 = [[str string] rangeOfString:@"协议"];
//    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range3];
    self.attributedText = str;
}

@end
